package Work0602;

import java.util.Scanner;

public class SupermarketTest {

	public static void main(String[] args) {
		Supermarket test = new Supermarket("合家福");
		test.show();
		test.addcard("黑猪", "z123456");
		test.addcard("灰猪", "d123456");
		Scanner in = new Scanner(System.in);
		while (true) {
			System.out.println("1.开卡  2.修改密码  3.积分累计  4.积分兑换  5.查询剩余积分  6.退出");
			System.out.println("请输入您的选择:");
			int q = in.nextInt();
			if (q == 1) {
				while (true) {
					System.out.print("请输入注册姓名:");
					String name = in.next();
					System.out.print("请输入注册密码:");
					String password = in.next();
					boolean p = test.addcard(name, password);
					if (p == false) {
						System.out.println("密码位数不得小于6位,请重新设置!");
					} else {
						break;
					}
				}
				System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			} else if (q == 2) {
				while (true) {
					System.out.print("请输入会员卡号:");
					int cardNumber = in.nextInt();
					System.out.print("请输入会员卡密码:");
					String password = in.next();
					if (test.check(cardNumber, password) == null) {
						System.out.print("卡号不存在或密码错误!");
					} else {
						System.out.print("请输入设置的新密码:");
						String newpassword = in.next();
						test.changePassword(cardNumber, password, newpassword);
						break;
					}
				}
				System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			} else if (q == 3) {
				while (true) {
					System.out.print("请输入会员卡号:");
					int cardNumber = in.nextInt();
					System.out.print("请输入会员卡密码:");
					String password = in.next();
					if (test.check(cardNumber, password) == null) {
						System.out.println("卡号不存在或密码错误!");
					} else {
						System.out.print("请输入消费的金额:");
						int money = in.nextInt();
						test.accumulation(cardNumber, password, money);
						break;
					}
				}
				System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			} else if (q == 4) {
				while (true) {
					System.out.print("请输入会员卡号:");
					int cardNumber = in.nextInt();
					System.out.print("请输入会员卡密码:");
					String password = in.next();
					if (test.check(cardNumber, password) == null) {
						System.out.println("卡号不存在或密码错误!");
					} else {
						System.out.print("请输入要兑换使用的积分(100积分抵用0.1元,不足100的积分不做抵用,必须为100的倍数):");
						int integral = in.nextInt();
						boolean w = test.exchange(cardNumber, password, integral);
						System.out.println(w ? ("您的消费金额中使用会员积分抵消" + integral / 100 * 0.1 + "元") : "输入的积分不符合规范!");
						break;
					}
				}
				System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			} else if (q == 5) {
				while (true) {
					System.out.print("请输入会员卡号:");
					int cardNumber = in.nextInt();
					System.out.print("请输入会员卡密码:");
					String password = in.next();
					if (test.check(cardNumber, password) == null) {
						System.out.println("卡号不存在或密码错误!");
					} else {
						test.queryPoints(cardNumber, password);
						break;
					}
				}
				System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			} else if (q == 6) {
				break;
			}
		}

	}

}
